package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Permission;
import cn.wolfcode.crm.domain.Classroom;
import cn.wolfcode.crm.mapper.ClassroomMapper;
import cn.wolfcode.crm.query.ClassroomQueryObject;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IClassroomService;
import cn.wolfcode.crm.util.PageResult;
import com.alibaba.druid.sql.PagerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClassroomServiceImpl implements IClassroomService {

    @Autowired
    private ClassroomMapper classroomMapper;

    @Override
    public void deleteByPrimaryKey(Long id) {
        classroomMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void saveOrUpdate(Classroom entity) {
        if(entity.getId() != null){
            classroomMapper.updateByPrimaryKey(entity);
        }else {
            classroomMapper.insert(entity);
        }

    }

    @Override
    public Classroom selectByPrimaryKey(Long id) {

        return classroomMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Classroom> selectAll() {
        return classroomMapper.selectAll();
    }

    @Override
    public PageResult query(ClassroomQueryObject qo) {
        int total = classroomMapper.queryForCount(qo);
        if (total == 0) {
            return PageResult.PAGERESULT_EMPTY;
        }
        return new PageResult(total,classroomMapper.query(qo));
    }

    @Override
    public void changState(Long id) {
        classroomMapper.changeState(id);
    }
}
